using UnityEngine;
using QFramework;
using Unity.Burst.Intrinsics;
using UnityEngine.UI;

namespace ProjectSurvivor
{
	public partial class FloattingTextController : ViewController
	{
		void Start()
		{
			FloattingText.Hide();
		}
		public static void Play(Vector2 position, string text,bool critical=false)
		{
			
			mDefult.FloattingText.InstantiateWithParent(mDefult.transform)
			.Position(position.x, position.y)
			.Self(f =>
			{
				var positionY = position.y;
				var textTrans = f.transform.Find("Text");
				var textComp = textTrans.GetComponent<Text>();
				textComp.text = text;
				// ActionKit.Delay(0.5f, () =>
				// {
				// 	textTrans.DestroyGameObjGracefully();
				// }).Start(textComp);
				if (critical)
				{
					textComp.color = Color.red;
				}
				
				ActionKit.Sequence()//注册帧更新/UI调试回调；
				.Lerp(0, 0.5f, 0.5f,p =>
				{
					f.PositionY(positionY * p);
					textComp.LocalScaleX(Mathf.Clamp01(p * 8));
					textComp.LocalScaleY(Mathf.Clamp01(p * 8));
				}).Delay(0.5f)
				.Lerp(1.0f,0,0.3f,p=>
				{
					textTrans.DestroyGameObjGracefully();
				}).Start(textComp);
			}).Show();
		}
		private static FloattingTextController mDefult;
		void Awake()
		{
			mDefult = this;
		}
        void OnDestroy()
        {
			mDefult = null;
        }
    }
}
